/* 
 * File:   OtherCPO.cpp
 * Author: Topher
 * 
 * Created on March 9, 2012, 7:20 AM
 */

#include "OtherCPO.h"


string OtherCPO::list(vector<Cart_item> item, vector<Product> prod)
{
    int ID=0;
    stringstream ss;
    
    
    cout<<"Please give Cart ID"<<endl;
    cin>>ID;
           
    for(int i=0;i<item.size();i++)
    {
        if(ID==item.at(i).get_cart_id())
        {
                ss<<"Product : "<<prod_name_by_ID(prod, item.at(i).get_prod_id())
                        <<"  |  Cost : "<<prod_cost_by_ID(prod, item.at(i).get_prod_id(), item.at(i).get_prod_qty())<<endl;
        }
    }
    
    string out=ss.str();
    return out;
}

void OtherCPO::addCart(vector<Cart> &cart, Customer cust, Date date)
{
    int CID=cust.get_cust_id();
    int cartID=0;
    Cart ncart;
    //Creates new cart ID
    for(int x=0;x<cart.size();x++)
    {
        if(cart.at(x).get_cart_id()>cartID)
            cartID=cart.at(x).get_cart_id();
    }
    cartID+=1;
    
    ncart=Cart(cartID, CID, date);
    cart.push_back(ncart);
}

void OtherCPO::remove(vector<Cart_item> &items, int CIID)
{
    bool itemGate = false;                                                                                                       
            for (vector<Cart_item>::iterator itemIter=items.begin();((itemIter!=items.end())&&!itemGate);++itemIter) 
	    {             
                if ((*itemIter).get_cart_item_id()==CIID) {                                                                                
                    items.erase(itemIter);                                                                                                
                    itemGate=true;                                                                                                     
                }                                                                                                                       
            }    
}

string OtherCPO::prod_name_by_ID(vector<Product> prod, int ID)
{
    string name;
    for(int x=0;x<prod.size();x++)
    {
        if(ID==prod.at(x).get_prod_id())
            name=prod.at(x).get_prod_name();
    }
    return name;
}

double OtherCPO::prod_cost_by_ID(vector<Product> prod, int ID, int qty)
{
    double price=0;
    for(int x=0;x<prod.size();x++)
    {
        if(ID==prod.at(x).get_prod_id())
            price=prod.at(x).get_prod_price()*qty;
    }
    return price;
}